package com.videoweb.controller;


import com.videoweb.annotation.Anonymous;
import com.videoweb.entity.dto.VideoItemDTO;
import com.videoweb.entity.dto.VideoUploadDTO;
import com.videoweb.service.IVideoService;
import com.videoweb.utils.AjaxResult;
import com.videoweb.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lmr
 * @since 2025-05-17
 */


@RestController
@RequestMapping("/video")
public class VideoController {

    @Autowired
    private IVideoService videoService;


    @PostMapping("/uploadVideo")
    public AjaxResult upLoadVideo(@RequestBody VideoUploadDTO videoUploadDTO) {

        System.out.println(videoUploadDTO);

        videoService.uploadVideo(videoUploadDTO);
        AjaxResult result = AjaxResult.success("文件上传成功,正在为你审核");
        System.out.println("fileUpload ok");

        return result;
    }


    @GetMapping("/getAllVideo")
    public AjaxResult getAllVideo() {

        AjaxResult result = AjaxResult.success();
        List<VideoItemDTO> videoItemDTOList = videoService.findVideoItem();
        result.put("videos", videoItemDTOList);
        return result;
    }


    //    根据视频的ID来得到视频
    @GetMapping("/{id}")
    public AjaxResult getVideoById(@PathVariable("id") Long videoId) {

        AjaxResult result = AjaxResult.success();
       VideoItemDTO videoItemDTOList = videoService.finVideoByVideoId(videoId);
        result.put("videos", videoItemDTOList);
        return result;
    }

//    根据视频的分类id来得到视频卡片

    @GetMapping("/category/{id}")
    public AjaxResult findVideoByCategoryId(@PathVariable("id") Long categoryId) {

        AjaxResult result = AjaxResult.success();
        List<VideoItemDTO> videoItemDTOList = videoService.findVideoByCategoryId(categoryId);
        result.put("videos", videoItemDTOList);
        return result;
    }


    //    根据视频的标签id来查找视频
    @GetMapping("/tag/{id}")
    public AjaxResult findVideoByTagID(@PathVariable("id") Long tagId) {

        AjaxResult result = AjaxResult.success();
        List<VideoItemDTO> videoItemDTOList = videoService.findVideoByTagID(tagId);
        result.put("videos", videoItemDTOList);
        return result;
    }

    //    根据视频的标签id来查找视频
    @GetMapping("/user/{id}")
    public AjaxResult findVideoByUserID(@PathVariable("id") Long userId) {

        AjaxResult result = AjaxResult.success();
        List<VideoItemDTO> videoItemDTOList = videoService.findVideoByUserID(userId);
        result.put("videos", videoItemDTOList);
        return result;
    }

//    //    根据收藏夹的id来查找视频

    @GetMapping("/favorites/{id}")
    public AjaxResult findVideoByFavoritesID(@PathVariable("id") Long favoritesId) {

        AjaxResult result = AjaxResult.success();
        List<VideoItemDTO> videoItemDTOList = videoService.finVideoByFavoritesId(favoritesId);
        result.put("videos", videoItemDTOList);
        return result;
    }






}
